const express = require("express");
const loginRouter = express.Router();
const adminServer = require("../../server/admin/indexServer");
const sendMsg = require("../reqSendResult");
const jwt = require("../jwt");
// 用户登录
loginRouter.post(
	"/",
	sendMsg.asyncHandler(async (req, res) => {
		const result = await adminServer.login(req.body.username, req.body.password);
    jwt.publish(res, result)
    // console.log(result, "token");
    return result
  }, "登录成功")
);
// 注册
loginRouter.post(
	"/register",
	sendMsg.asyncHandler(async (req, res) => {
    console.log(req.body);
    if(req.body.name && req.body.phone && req.body.loginName && req.body.loginPwd){
      const result = await adminServer.register(req);
      return result
    } else {
      throw '请填写完整数据'
    }
  }, "注册成功")
);

module.exports = loginRouter;
